<!DOCTYPE HTML>
<html>
   <head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>知果汇</title>
		<link href="_CSS_/bootstrap.min.css" rel="stylesheet">
		<link href="_CSS_/simple-line-icons.css" rel="stylesheet">
		<link href="_CSS_/font-awesome.min.css" rel="stylesheet">
		<link href="_CSS_/jasny-bootstrap.min.css" rel="stylesheet">
		<link rel="stylesheet" href="_CSS_/nanoscroller.css">
		<link href="_CSS_/style.css" rel="stylesheet">
		<link rel="stylesheet" type="text/css" href="_CSS_/jquery-ui.css">
		<!--[if lt IE 9]>
		  <script src="js/html5shiv.min.js"></script>
		  <script src="js/respond.min.js"></script>
		<![endif]-->
		<style type="text/css">
		    body{background-color: #ffffff;min-width: 500px;}
			.row{margin-left: 0px;margin-right: 0px;min-width: 500px;}
			.radio-box{display:inline-block;width: 64px;}
			.formControls{padding-right:50px; position: relative;}
			.textarea {height: 100px;resize: none;font-size: 14px;padding: 4px;}
            .textarea-numberbar {position: absolute;right: 70px;bottom: 5px;z-index: 1;margin-bottom: 0;}
		</style>
    </head>
	<body>
	<article class="page-container">
		<form class="form form-horizontal" id="form-admin-add">
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">字典名称：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" placeholder="" id="systemname" name="systemname">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">所属模块：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<span class="select-box">
						<p id="tabname" >
						</p>
					</span> 
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">上级字典：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<span class="select-box">
						<p id="fieldname">
						</p>
					</span> 
				</div>
			</div>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input class="btn btn-primary radius" type="button" id="sub" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
					<button class="btn btn-cancel radius" id="btn-cancel" style="color: #ffffff;background-color: #a0a0a0;width: 72px;">取消</button>
				</div>
			</div>
		</form>
	</article>

    <script src="_JS_/jquery.min.js"></script>
    <script src="_JS_/bootstrap.min.js"></script>
    <script src="_JS_/jasny-bootstrap.min.js"></script>
    <script src="_JS_/jquery.slimscroll.min.js"></script>
    <script src="_JS_/jquery.nanoscroller.min.js"></script>
    <script src="_JS_/metismenu.min.js"></script>
    <script src="_JS_/float-custom.js"></script>
    <script type="text/javascript" src="_JS_/layer/layer.js"></script>
    <script type="text/javascript" src="_JS_/jquery.validation/1.14.0/jquery.validate.min.js"></script> 
    <script type="text/javascript" src="_JS_/jquery.validation/1.14.0/validate-methods.js"></script> 
    <script type="text/javascript" src="_JS_/jquery.validation/1.14.0/messages_zh.min.js"></script> 

	<script type="text/javascript">
	/*textarea 字数限制*/
	function textarealength(obj,maxlength){
		var v = $(obj).val();
		var l = v.length;
		if( l > maxlength){
			v = v.substring(0,maxlength);
			$(obj).val(v);
		}
		$(obj).parent().find(".textarea-length").text(v.length);
	}
	$(function(){
		var url=window.location.href;
        id = url.split("=")[1];
		$("#form-admin-add").validate({
			rules:{
				systemname:{
					required:true,
					minlength:2,
					maxlength:16
				},
				tabname:{
					required:true,
				},
				fieldname:{
					required:true,
				},
			},
			onkeyup:false,
			focusCleanup:true,
			success:"valid",
			submitHandler:function(form){
				
			}
		});

		$("#btn-cancel").click(function(){
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		});


		/*获取上级目录和所属模块信息*/
		$.ajax({ 
	        type: "get", 
	        url: "{:url('api/Dictionary/get_info')}",
	        dataType: 'jsonp',
            jsonp:'callback',
	        data:{'id':id},
	        success: function (msg) {
	            if(msg.code == 200){ 
	            	var index = parent.layer.getFrameIndex(window.name);
					//parent.getlist(1);
					var tabname = msg['data']['t_name'];
						fieldname = msg['data']['up_name'];
						systemname = msg['data']['name'];
					$('#tabname').html(tabname);
					$('#fieldname').html(fieldname);
					$('#systemname').val(systemname);
					// parent.layer.close(index);
	            }
	            if(msg.code==1000){
	                layer.msg('添加失败!',{icon:1,time:1000});
	            }
	        }
	    });

		/*提交编辑*/
		$('#sub').click(function(){
			// alert(id);return false;
			var name = $('#systemname').val();
			if(name == null || name == ''){
				layer.msg('字典名称不能为空!',{icon:2,time:1000});
			}
			$.ajax({ 
		        type: "get", 
		        url: "{:url('api/Dictionary/edit')}",
		        dataType: 'jsonp',
	            jsonp:'callback',
		        data:{'id':id,'name':name},
		        success: function (msg) {
		            if(msg.code == 200){ 
		            	var index = parent.layer.getFrameIndex(window.name);
						layer.msg('提交成功!',{icon:1,time:1000});
						parent.layer.close(index);
						parent.location.reload();
		            }
		            if(msg.code==1000){
		                layer.msg('提交失败!',{icon:2,time:1000});
		            }
		        },
		        error:function(){
		        	layer.msg('网络错误!');
		        }
		    });
		}); 

	});


	
	
	</script> 
</body>
</html>